package backend.model.admin;

import backend.model.base.DBModel;
import org.hibernate.annotations.NamedQueries;
import org.hibernate.annotations.NamedQuery;

import javax.persistence.*;

@NamedQueries({ @NamedQuery(name = "findAllSfis", query = "from Sfi"),
                @NamedQuery(name = "findAllActiveSfis", query = "from Sfi where isActive = true"),
                @NamedQuery(name = "findSfiByName", query = "from Sfi where name = :name")
})
@Entity
@Table(name = "sfi")
public class Sfi extends DBModel {

    @Id
    @GeneratedValue
    @Column(name = "id")
    private int id;

    @Column(name = "name")
    private String name;

    @Column(name = "description")
    private String description;

    @ManyToOne
    @JoinColumn(name = "activity_id")
    private Activity activity;

    @ManyToOne
    @JoinColumn(name = "department_id")
    private Department department;

    @Column(name = "is_active")
    private boolean isActive;

    @Override
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Activity getActivity() {
        return activity;
    }

    public void setActivity(Activity activity) {
        this.activity = activity;
    }

    public Department getDepartment() {
        return department;
    }

    public void setDepartment(Department department) {
        this.department = department;
    }

    public boolean getIsActive() {
        return isActive;
    }

    public void setIsActive(boolean isActive) {
        this.isActive = isActive;
    }

    @Override
    public String getDisplayLabel() {
        return name;
    }

    @Override
    public int compareTo(Object o) {
        if (!(o instanceof Sfi)) {
            return -1;
        } else {
            Sfi otherSfi = (Sfi) o;
            return getDisplayLabel().compareTo(otherSfi.getDisplayLabel());
        }
    }
}
